package cn.app.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.app.dao.appinfo.AppInfoDao;
import cn.app.entity.AppInfo;
import cn.app.service.AppInfoService;
import cn.app.utils.PageBean;

@Service
@Transactional
public class AppInfoServiceImpl implements AppInfoService {
	
	@Autowired
	private AppInfoDao appInfoDao;

	@Override
	public PageBean<AppInfo> findAllByCondition(Map<String, Object> map) {
		
		//页面会传来2个数据当前页,每页显示个数
		Integer currentPage = (Integer) map.get("currentPage");		//2
		Integer pageSize = (Integer) map.get("pageSize");			//null
		//数据总条数
		Integer totalCount = appInfoDao.findAppInfoCount(map);		//13
		//创建工具类
		PageBean<AppInfo> pageBean = new PageBean<>(currentPage, pageSize, totalCount);
		//查询出对应页数的appINfo的信息
		map.put("startIndex", pageBean.getStartIndex());
		map.put("pageSize", pageBean.getPageSize());
		List<AppInfo> pageList = appInfoDao.findAllByCondition(map);
		//讲查询出的pageList放到
		pageBean.setPageList(pageList);
		return pageBean;
	}

	@Override
	public Integer findAppInfoByAPKName(String apkName) {
		List<AppInfo> appInfo = appInfoDao.findAppInfoByAPKName(apkName);
		if(appInfo.size() > 0){
			//已经存在
			return 1;
		}else{
			//可以使用
			return 0;
		}
	}

	@Override
	public Integer addAppInfo(AppInfo appInfo) {
		return appInfoDao.addAppInfo(appInfo);
	}

	@Override
	public AppInfo findAppInfoById(Integer id) {
		return appInfoDao.findAppInfoById(id);
	}
}
